package enumeration;

import org.w3c.dom.ls.LSOutput;

/**
 * @Package: enumeration
 * @ClassName: EnumEnumeration
 * @Author: x2606
 * @CreateTime: 2022/3/12 17:29
 * @Description: enum关键字枚举
 */

public class EnumEnumeration {
    public static void main(String[] args) {
        System.out.println(Season02.SUMMER);
        System.out.println(Season02.WINTER);

        Season02 spring = Season02.SPRING;
        //枚举类的常用方法

        //输出对象名字
        System.out.println(spring.name());
        //输出对象次序，即编号
        System.out.println(spring.ordinal());
        //Season02.values()返回整个枚举对象数组
        for (Season02 season:Season02.values()) {
            System.out.println(season);
        }
        //将字符串转换为名字相同的枚举对象，没有相同就报异常
        Season02 Spring = Season02.valueOf("SPRING");
        System.out.println(Spring);
        //compareTo比较两个枚举常量的编号,返回编号差值
        System.out.println(spring.compareTo(Season02.SUMMER));
    }
}
//关键字实现枚举类
//使用Enum代替class关键字

enum Season02 {
    //1.使用 常量名(参数列表) 直接实例化枚举对象。
    //2.定义常量对象可以有多个，用,号隔开
    //3.定义常量对象必须放在第一排。
    SPRING ("春天","温暖"), SUMMER("夏天","炎热"), AUTUMN("秋天","凉爽"), WINTER("冬天","寒冷");
    private String name;
    private String desc;

    private Season02(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    @Override
    public String toString() {
        return "Season02{" +
                "name='" + name + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }
}
